/*
 * Copyright (C) 2012, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.model;

import xowl.utils.config.Section;

/**
 *
 * @author Laurent WOUTERS
 */
public class DiagramRelation extends DiagramElement {
    private String parentIRI;
    private String objIRI;
    private int originPort;
    private int targetPort;
    
    public String getParentIRI() { return parentIRI; }
    public String getObjectIRI() { return objIRI; }
    public int getOriginPort() { return originPort; }
    public int getTargetPort() { return targetPort; }
    
    public DiagramRelation(String parentIRI, String objIRI, int originPort, int targetPort) {
        super(generateID("Relation"));
        this.parentIRI = parentIRI;
        this.objIRI = objIRI;
        this.originPort = originPort;
        this.targetPort = targetPort;
    }
    
    public DiagramRelation(String id, Section section) {
        super(id);
        this.parentIRI = section.getValue(id + ".piri");
        this.objIRI = section.getValue(id + ".iri");
        String strorigin = section.getValue(id + ".origin");
        String strtarget = section.getValue(id + ".target");
        this.originPort = Integer.parseInt(strorigin);
        this.targetPort = Integer.parseInt(strtarget);
    }
    
    public void save(Section section) {
        section.addValue(id + ".piri", parentIRI);
        section.addValue(id + ".iri", objIRI);
        section.addValue(id + ".origin", Integer.toString(originPort));
        section.addValue(id + ".target", Integer.toString(targetPort));
    }
}
